import scrapy
from selenium.webdriver import Chrome
from KingImg.items import KingimgItem


class KingimgSpider(scrapy.Spider):
    """下载王者壁纸"""
    name = 'kingimg'
    # allowed_domains = ['www.c.com']
    start_urls = ['https://pvp.qq.com/web201605/wallpaper.shtml']
    page = 2
    
    def __init__(self):
        self.driver = Chrome(executable_path='E:\\python\程序\\net_spyder\\chromedriver.exe')
        self.driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
            "source": """
                Object.defineProperty(navigator, 'webdriver', {
                get: () => undefined
                })
            """
            })
        
    def parse(self, response):
        for div in response.xpath('//*[@id="Work_List_Container_267733"]/div'):
            name = div.xpath('./h4/a/text()').extract_first()
            url = div.xpath('./ul/li[5]/a/@href').extract_first()
            # print(name, url)
            item = KingimgItem()
            item['name'] = name
            item['url'] = url
            yield item
            
            

            
